package com.blrs.service.project.evaluation.impl;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.blrs.common.utils.SecurityUtils;
import com.blrs.common.utils.StringUtils;
import com.blrs.domain.ProjectInfo;
import com.blrs.domain.vo.BusinessMainClassVo;
import com.blrs.system.domain.SysUploadFile;
import com.blrs.system.mapper.SysUploadFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.blrs.mapper.ProjectConfirmationEvaluationMapper;
import com.blrs.domain.ProjectConfirmationEvaluation;
import com.blrs.service.project.evaluation.IProjectConfirmationEvaluationService;

/**
 * 项目确认及评价Service业务层处理
 * 
 * @author wangchao
 * @date 2023-12-11
 */
@Service
public class ProjectConfirmationEvaluationServiceImpl implements IProjectConfirmationEvaluationService 
{
    @Autowired
    private ProjectConfirmationEvaluationMapper projectConfirmationEvaluationMapper;
    @Autowired
    private SysUploadFileMapper sysUploadFileMapper;


    //资质/文控中心 同步到附件
    @Override
    public int evaluateWK(SysUploadFile sysUploadFile) {
        int count = 0;
        String fileId = sysUploadFile.getBusinessId();
        SysUploadFile fList = sysUploadFileMapper.selectSysUploadFileById(sysUploadFile.getId());
        SysUploadFile newFile = new SysUploadFile();
        newFile.setId(UUID.randomUUID().toString());
        if(StringUtils.isNotEmpty(sysUploadFile.getContent()) && "".equals(sysUploadFile.getContent().trim())){
            newFile.setBusinessId(sysUploadFile.getContent());
        }else {
            newFile.setBusinessId(fileId);
        }
        if(sysUploadFile.getFileSize().equals("1")){//文控
            newFile.setBusinessCode("internal");
            newFile.setFileName(sysUploadFile.getNewFileName());
        }else if(sysUploadFile.getFileSize().equals("2")){//资质
            newFile.setBusinessCode("honor");
            newFile.setFileName(fList.getFileName());
        }
        newFile.setNewFileName(fList.getNewFileName());
        newFile.setFileType(fList.getFileType());
        newFile.setFileSize(fList.getFileSize());
        newFile.setUrl(fList.getUrl());
        newFile.setPhyPath(fList.getPhyPath());
        newFile.setContent(fList.getContent());
        newFile.setDelFlag(0);
        newFile.setCreationTime(new Timestamp(new Date().getTime()));
        newFile.setOperateTime(new Timestamp(new Date().getTime()));
        newFile.setCreationBy(SecurityUtils.getUsername());
        newFile.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        newFile.setOperateId(String.valueOf(SecurityUtils.getUserId()));
        newFile.setOrganizationId(SecurityUtils.getOrgId());
        newFile.setOrganizationName(SecurityUtils.getOrgName());
        newFile.setDepartmentId(SecurityUtils.getDeptId().toString());
        newFile.setDepartmentName(SecurityUtils.getLoginUser().getUser().getDept().getDeptName());
        count = sysUploadFileMapper.insertSysUploadFile(newFile);
        return count;
    }

    /**
     * 查询项目确认及评价
     * 
     * @param id 项目确认及评价主键
     * @return 项目确认及评价
     */
    @Override
    public ProjectConfirmationEvaluation selectProjectConfirmationEvaluationById(String id)
    {
        return projectConfirmationEvaluationMapper.selectProjectConfirmationEvaluationById(id);
    }

    /**
     * 查询项目确认及评价列表
     * 
     * @param projectConfirmationEvaluation 项目确认及评价
     * @return 项目确认及评价
     */
    @Override
    public List<ProjectConfirmationEvaluation> selectProjectConfirmationEvaluationList(ProjectConfirmationEvaluation projectConfirmationEvaluation)
    {
        return projectConfirmationEvaluationMapper.selectProjectConfirmationEvaluationList(projectConfirmationEvaluation);
    }

    /**
     * 新增项目确认及评价
     * 
     * @param projectConfirmationEvaluation 项目确认及评价
     * @return 结果
     */
    @Override
    public int insertProjectConfirmationEvaluation(ProjectConfirmationEvaluation projectConfirmationEvaluation)
    {
        projectConfirmationEvaluation.setId(UUID.randomUUID().toString());
        projectConfirmationEvaluation.setCreationId(SecurityUtils.getUserId());
        projectConfirmationEvaluation.setCreationName(SecurityUtils.getUsername());
        projectConfirmationEvaluation.setCreationTime(new Timestamp(new Date().getTime()));
        projectConfirmationEvaluation.setOperateId(SecurityUtils.getUserId());
        projectConfirmationEvaluation.setOperateName(SecurityUtils.getUsername());
        projectConfirmationEvaluation.setOperateTime(new Timestamp(new Date().getTime()));
        projectConfirmationEvaluation.setOrganizationId(SecurityUtils.getOrgId());
        projectConfirmationEvaluation.setOrganizationName(SecurityUtils.getOrgName());
        projectConfirmationEvaluation.setDepartmentId(SecurityUtils.getDeptId());
        projectConfirmationEvaluation.setDepartmentName(SecurityUtils.getLoginUser().getUser().getDept().getDeptName());
        return projectConfirmationEvaluationMapper.insertProjectConfirmationEvaluation(projectConfirmationEvaluation);
    }

    /**
     * 修改项目确认及评价
     * 
     * @param projectConfirmationEvaluation 项目确认及评价
     * @return 结果
     */
    @Override
    public int updateProjectConfirmationEvaluation(ProjectConfirmationEvaluation projectConfirmationEvaluation)
    {
        return projectConfirmationEvaluationMapper.updateProjectConfirmationEvaluation(projectConfirmationEvaluation);
    }

    /**
     * 批量删除项目确认及评价
     * 
     * @param ids 需要删除的项目确认及评价主键
     * @return 结果
     */
    @Override
    public int deleteProjectConfirmationEvaluationByIds(String[] ids)
    {
        return projectConfirmationEvaluationMapper.deleteProjectConfirmationEvaluationByIds(ids);
    }

    /**
     * 删除项目确认及评价信息
     * 
     * @param id 项目确认及评价主键
     * @return 结果
     */
    @Override
    public int deleteProjectConfirmationEvaluationById(String id)
    {
        return projectConfirmationEvaluationMapper.deleteProjectConfirmationEvaluationById(id);
    }
}
